package com.lagou.homework.zookeeper;

import com.alibaba.fastjson.JSONObject;
import org.I0Itec.zkclient.ZkClient;
import org.apache.zookeeper.data.Stat;

/**
 * @author shiyuhou
 * @version 1.0
 * @description: TODO
 * @date 6/22/21 5:56 PM
 */
public class MysqlConfigChange {

    static ZkClient zkClient = null;

    public static void main(String[] args) {

        //创建zk客户端
        zkClient = new ZkClient("localhost:2181");
        if(!zkClient.exists("/mysql")){
            zkClient.createPersistent("/mysql");
        }
        //创建临时顺序节点，保存数据源相关信息
        JSONObject json=new JSONObject();
        json.put("url","jdbc:mysql://localhost:3306/test?useSSL=false");
        json.put("username","root");
        json.put("password","12345678");
        Stat stat = zkClient.writeData("/mysql/localhost", json.toJSONString());
        System.out.println("---->>> 连接修改成功， stat信息="+stat.toString()+"， 节点信息："+json.toJSONString());
    }
}
